// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import App from './App';
import router from './router';
import { Notify } from 'vant';
import Vant from 'vant';
import 'vant/lib/index.css';

Vue.use(Vant);

Vue.config.productionTip = false;

import axios from 'axios';
const service = axios.create({
  baseURL: "/",
  timeout: 500000,  // 请求超时时间
  //headers: {'Content-Type': 'multipart/form-data'}
});

service.interceptors.response.use(response=>{
  if(typeof response.data.msg == "string" && vm.$route.name != "/login" && response.data.msg == "no-login"){
    vm.$router.replace({path:"/login",query:{backTo:vm.$route.path}});
    return false;
  }else if(typeof response.data.msg == 'undefined'){
    Notify({ type: 'danger', message: '系统返回数据错误' });
    return false;
  }
  return response.data;
},error => {
  if(typeof error.response == 'undefined'|| error.response.status != 422) Notify({ type: 'danger', message: '网络请求出错'});
  return Promise.reject(error.response.data);
});

Vue.prototype.$axios = service;

window.loginInfo = null;

/* eslint-disable no-new */
var vm = new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
